package com.project.market.service.impl;

import com.github.pagehelper.PageHelper;
import com.project.market.db.domain.MarketFeedback;
import com.project.market.db.domain.MarketFeedbackExample;
import com.project.market.db.domain.MarketSearchHistory;
import com.project.market.db.domain.MarketSearchHistoryExample;
import com.project.market.db.mapper.MarketFeedbackMapper;
import com.project.market.db.mapper.MarketSearchHistoryMapper;
import com.project.market.service.AdminFeedbackService;
import com.project.market.util.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class AdminFeedbackServiceImpl implements AdminFeedbackService {
    @Override
    public List<MarketFeedback> list(String page, String limit, String sort, String order,String username,String id) {

        SqlSession session = MybatisUtil.getSession();
        MarketFeedbackMapper mapper = session.getMapper(MarketFeedbackMapper.class);
        MarketFeedbackExample example = new MarketFeedbackExample();
        MarketFeedbackExample.Criteria criteria = example.createCriteria();
        criteria.andDeletedEqualTo(false);

        if(username!=null){
            criteria.andUsernameLike("%" + username +"%");
        }
        if(id!=null && !("".equals(id))){
            try{
            criteria.andIdEqualTo(Integer.valueOf(id));
            } catch (Exception e) {
                return null;
            }
        }

        List<MarketFeedback> list = mapper.selectByExample(example);

        PageHelper.startPage(Integer.valueOf(page),Integer.valueOf(limit));

        session.commit();
        session.close();
        return list;
    }
}
